package com.daoImpl;

import java.util.List;

import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.bean.ProcureProductSku;
import com.dao.ProcureProductSkuDao;

/**
 * A data access object (DAO) providing persistence and search support for
 * ProcureProductSku entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.bean.ProcureProductSku
 * @author MyEclipse Persistence Tools
 */
public class ProcureProductSkuDaoImpl extends HibernateDaoSupport implements ProcureProductSkuDao {
	private static final Logger log = LoggerFactory
			.getLogger(ProcureProductSkuDaoImpl.class);
	// property constants
	public static final String PROC_ID = "procId";
	public static final String PRODUCT_CODE = "productCode";
	public static final String SKU_CODE = "skuCode";
	public static final String COLO = "colo";
	public static final String CONA = "cona";
	public static final String SZID = "szid";
	public static final String COLO_ID = "coloId";
	public static final String SZCO = "szco";
	public static final String PURCHASE_NUM = "purchaseNum";

	protected void initDao() {
		// do nothing
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#save(com.bean.ProcureProductSku)
	 */
	@Override
	public void save(ProcureProductSku transientInstance) {
		log.debug("saving ProcureProductSku instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#delete(com.bean.ProcureProductSku)
	 */
	@Override
	public void delete(ProcureProductSku persistentInstance) {
		log.debug("deleting ProcureProductSku instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#findById(java.lang.Integer)
	 */
	@Override
	public ProcureProductSku findById(java.lang.Integer id) {
		log.debug("getting ProcureProductSku instance with id: " + id);
		try {
			ProcureProductSku instance = (ProcureProductSku) getHibernateTemplate()
					.get("com.bean.ProcureProductSku", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#findByExample(com.bean.ProcureProductSku)
	 */
	@Override
	public List findByExample(ProcureProductSku instance) {
		log.debug("finding ProcureProductSku instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#findByProperty(java.lang.String, java.lang.Object)
	 */
	@Override
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ProcureProductSku instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from ProcureProductSku as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#findByProcId(java.lang.Object)
	 */
	@Override
	public List findByProcId(Object procId) {
		return findByProperty(PROC_ID, procId);
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#findByProductCode(java.lang.Object)
	 */
	@Override
	public List findByProductCode(Object productCode) {
		return findByProperty(PRODUCT_CODE, productCode);
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#findBySkuCode(java.lang.Object)
	 */
	@Override
	public List findBySkuCode(Object skuCode) {
		return findByProperty(SKU_CODE, skuCode);
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#findByColo(java.lang.Object)
	 */
	@Override
	public List findByColo(Object colo) {
		return findByProperty(COLO, colo);
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#findByCona(java.lang.Object)
	 */
	@Override
	public List findByCona(Object cona) {
		return findByProperty(CONA, cona);
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#findBySzid(java.lang.Object)
	 */
	@Override
	public List findBySzid(Object szid) {
		return findByProperty(SZID, szid);
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#findByColoId(java.lang.Object)
	 */
	@Override
	public List findByColoId(Object coloId) {
		return findByProperty(COLO_ID, coloId);
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#findBySzco(java.lang.Object)
	 */
	@Override
	public List findBySzco(Object szco) {
		return findByProperty(SZCO, szco);
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#findByPurchaseNum(java.lang.Object)
	 */
	@Override
	public List findByPurchaseNum(Object purchaseNum) {
		return findByProperty(PURCHASE_NUM, purchaseNum);
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#findAll()
	 */
	@Override
	public List findAll() {
		log.debug("finding all ProcureProductSku instances");
		try {
			String queryString = "from ProcureProductSku";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#merge(com.bean.ProcureProductSku)
	 */
	@Override
	public ProcureProductSku merge(ProcureProductSku detachedInstance) {
		log.debug("merging ProcureProductSku instance");
		try {
			ProcureProductSku result = (ProcureProductSku) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#attachDirty(com.bean.ProcureProductSku)
	 */
	@Override
	public void attachDirty(ProcureProductSku instance) {
		log.debug("attaching dirty ProcureProductSku instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.bean.ProcureProductSkuDao#attachClean(com.bean.ProcureProductSku)
	 */
	@Override
	public void attachClean(ProcureProductSku instance) {
		log.debug("attaching clean ProcureProductSku instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static ProcureProductSkuDao getFromApplicationContext(
			ApplicationContext ctx) {
		return (ProcureProductSkuDao) ctx.getBean("procureProductSkuDao");
	}
}